﻿var currentpos;
function currentDate() {
    var now = new Date();
    var yy = now.getFullYear();
    var date = now.getDate();
    var month = now.getMonth() + 1;
    var hh = now.getHours();
    var mm = now.getMinutes();
    var ss = now.getSeconds();

    return yy + '-' + month + '-' + date + ' ' + hh + ':' + mm + ':' + ss;

}
function addInfo(Info, InfoID) {
    if ($("#writeroot").children().length >= 100) {
        $("#writeroot").children().remove();
    }
    var newDiv = '<div name="' + InfoID + '" id="' + InfoID + '">&nbsp;&nbsp;>&nbsp;&nbsp;' + Info + '  &nbsp;&nbsp;<i>' + currentDate() + '</i></div>';
    var tool = $("#writeroot");
    tool.append(newDiv);
    scroll(0, document.body.scrollHeight);
}
function addInfoNewStyle(Info, InfoID, InfoAdd) {
    var Panel = $('<div topDiv="true" isGetData="false" success="false"  name="' + InfoID + '" id="' + InfoID + '" style="clear:both;"></div>');
    $('<div style=" float:left; width:260px; padding-left:10px;"></div>').html(Info).appendTo(Panel);
    $('<div style=" float:left; width:150px; padding-left:10px;"></div>').html(currentDate()).appendTo(Panel);
    var TipDiv;
    if (InfoAdd) {
        TipDiv = $('<div name="TipDiv" style=" float:left; width:200px; padding-left:10px;"></div>').html('<span  style=" color:blue; font-weight:bold;  font-size:12px; text-align:justify;" ><img src="/App_Themes/Classic/images/loading.gif" height="10px;" />&nbsp;&nbsp;' + InfoAdd + '</span>').appendTo(Panel);
    }
    else {
        TipDiv = $('<div name="TipDiv" style=" float:left; width:200px; padding-left:10px;"></div>').html('<span  style=" color:Green; font-weight:bold;  font-size:12px; text-align:justify;" ><img src="/App_Themes/Classic/images/loading.gif"  height="10px;"/>&nbsp;&nbsp;任务已加入执行队列......</span>').appendTo(Panel);
    }
    $("#writeroot").append(Panel);
    /*
    scroll(0, document.body.scrollHeight);
    var newDiv = '<div name="' + InfoID + '" id="' + InfoID + '">&nbsp;&nbsp;>&nbsp;&nbsp;' + Info + '  &nbsp;&nbsp;<i>' + currentDate() + '</i></div>';
    var tool = $("#writeroot");
    tool.append(newDiv);
    scroll(0, document.body.scrollHeight); 
    */
}
function SetInfo(id, StatusValue) {
    var error = '<span  style=" color:red; font-weight:bold;  font-size:12px; text-align:justify;" > × 执行失败</span>';
    var success = '<span  style=" color:black; font-weight:bold;  font-size:12px; text-align:justify;" > √ 执行成功</span>';
    var Normaltimeout = 5000;
    var Errortimeout = 10000;
    var timeout = 5000;
    if ($("#" + id).length > 0) {
        $("#" + id).attr("isGetData", "true");
        if (StatusValue == "success") {
            $("#" + id).find("div[name='TipDiv']").html(success);
            $("#" + id).attr("success", "true");
        }
        else {
            $("#" + id).find("div[name='TipDiv']").html(error);
            $("#" + id).attr("success", "false");
            timeout = Errortimeout;
        }
    }
    setTimeout(function () { RemoveOneDiv($("#" + id)); }, timeout);
    $("div[topDiv='true'][isGetData='false']").each(function () {
        var self = this;
        if (parseInt($(self).attr("id")) < parseInt(id)) {
            $(self).attr("isGetData", "true").attr("topDiv", "false").attr("success", "true");
            $(self).find("div[name='TipDiv']").html(success);
            setTimeout(function () { RemoveOneDiv($(self)); }, Normaltimeout);
        }
        else
            return;
    });
}
function RemoveOneDiv(divControl) {
    $(divControl).remove();
    var self_Id = parseInt($(divControl).attr("id"));
    if (self_Id > 0) {
        $("div[topDiv='false'][isGetData='true'][success='true']").each(function () {
            var self = this;
            if (parseInt($(self).attr("id")) < parseInt(self_Id)) {
                $(self).remove();
            }
            else
                return;
        });
    }
}
function CancelMyTask() {
    if (confirm("确定取消所有任务吗？")) {
        top.TaskRunTutiThread.CancelMyTask();
    }
}
function ClearAllInfo() {
    $("#writeroot").children().remove();
}